<template>
  <div class="icon-list app-container">
    <nav-bar title="图标" leftArrow />

    <scroll class="scroll" :data="List" ref="scroll">
      <ul class="list" :style="{backgroundColor: BgColor}">
        <li class="item" v-for="item in List" :key="item.icon_id" @click="select(item)">
          <icon-svg :icon-class="item.font_class" :color="color" />
          <div class="name" v-text="item.name" />
        </li>
      </ul>
    </scroll>
    <input v-model="copyInput" readonly ref="copyInput">
  </div>
</template>

<script>
import iconfont from './iconfont.json'

export default {
  name: 'icon-list',
  data () {
    return {
      List: iconfont.glyphs,
      copyInput: '',
      BgColor: '#f5f5f5',
      color: '#333333'
      // color: '#f2f2f2'
    }
  },
  created () {
    console.log('图标列表：\n', this.List)
  },
  methods: {
    select (data) {
      this.copyInput = data.font_class
      if (this.$refs.copyInput) {
        this.$refs.copyInput.select()
        document.execCommand('copy')
      }
    }
  }
}
</script>

<style scoped>
  .scroll {
    height: calc(100% - var(--nav-bar-height) - var(--status-bar-height));
  }
  .list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    background: #f5f5f5;
    color: #222222;
  }
  .list .item {
    padding: 12px 0;
    width: 0;
    flex-basis: 25%;
    display: flex;
    flex-flow: column;
    align-items: center;
  }
  .list .item .icon-svg {
    font-size: 50px;
    animation: changeColor 5s linear infinite;
  }
  .list .item .name {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  @keyframes changeColor {
    0% { filter: hue-rotate(0deg) }
    100% { filter: hue-rotate(360deg) }
  }

</style>
